package RequestHandler;

import java.util.*;
import java.util.concurrent.locks.*;
import Request.*;

public class RequestQueue {
    Queue<Request> rq =new LinkedList<Request>();
    private final Lock qlock = new ReentrantLock();
    
    public void addRequest(Request request) {
        qlock.lock();
        try {
            rq.offer(request);
        }
        finally {
            qlock.unlock();
        }
    }
    
    public Request getNextRequest() {
        Request request = null;
        qlock.lock();
        try {
            //System.out.println("queue before: " + rq.size());
            request = rq.poll();
            //System.out.println("queue after: " + rq.size());
        }
        finally {
            qlock.unlock();
        }    
        return request;
    }
}